<?php
import('@.Action.PublicAction');
class PersonAction extends Action
{
	function changeRight(){
		$Dao = D("UrightView");
		import("ORG.Util.HashMap");
		$maptmp=new HashMap();
		$maptmp->put("USER_ID",array('eq',$_SESSION['USER_ID']));
		$voList=$Dao->findAll($maptmp,'*');
		$this->assign("list",$voList);
		$this->display();
	}
	function doChangeRight(){
		$Right=D("Uright");
		$vo=$Right->find("`USER_ID`='".$_SESSION['USER_ID']."' and `ID`='".$_GET['id']."'");
		if($vo){
			//注销权限
			unset($_SESSION['user_right']);
			unset($_SESSION['rightInfo']);
			unset($_SESSION['dm_yx']);
			unset($_SESSION['dm_zy']);
			unset($_SESSION['dm_bj']);
			//载入角色信息
			$Role = D("Role");
			$rolevo=$Role->find("`id`='".$vo['ROLE_ID']."'");
			//设置权限范围（角色,学院，专业，班级）
			$_SESSION['user_right']	=	$vo['ROLE_ID'];
			
			//班主任	
			if ( $vo['ROLE_ID'] == 6)
			{
				$_SESSION['dm_yx']	=	$vo['DM_YX'];
				$_SESSION['dm_zy']	=	$vo['DM_ZY'];
				$_SESSION['dm_bj']	=	$vo['DM_BJ'];
				$_SESSION['rightInfo']=$rolevo['name'].":".$vo['YX']."-".$vo['ZY']."-".$vo['BJ'];			
			//系统管理员
			}
			elseif($vo['ROLE_ID'] == 1)
			{
				$_SESSION['rightInfo']=$rolevo['name'];			
			//其他角色
			}
			else
			{
				$_SESSION['dm_yx']	=	$vo['DM_YX'];				
				$_SESSION['rightInfo']=$rolevo['name'].":".$vo['YX'];					
			}

			$this->assign("jumpUrl",__URL__."/changeRight"); 			
			$this->success('切换权限成功！');
		}else{
			$this->error('错误权限！');
		}
	}
	function doEditPassword(){
		$Dao=D("User");
		$user=$Dao->find($_SESSION['USER_ID']);
		if(md5($_POST['password'])!=$user['password']){
			$this->error("原密码错误！"); 
		}
		if($_POST['newpassword']!=$_POST['repassword']){
			$this->error("原密码错误！"); 
		}
		$Dao->password=md5($_POST['newpassword']);
		$rs=$Dao->save();		
		if($rs){ 
			$this->success("修改密码成功!"); 
		}else{ 
			$this->error("修改密码失败"); 
		} 
	}
}
?>